package com.ruoyi.lvlian.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lvlian.mapper.WeighMapper;
import com.ruoyi.lvlian.domain.Weigh;
import com.ruoyi.lvlian.service.IWeighService;

/**
 * 过磅单Service业务层处理
 *
 * @author liyuxi
 * @date 2025-06-06
 */
@Service
public class WeighServiceImpl implements IWeighService {
    @Autowired
    private WeighMapper weighMapper;

    /**
     * 查询过磅单
     *
     * @param id 过磅单主键
     * @return 过磅单
     */
    @Override
    public Weigh selectWeighById(String id) {
        return weighMapper.selectWeighById(id);
    }

    /**
     * 查询过磅单列表
     *
     * @param weigh 过磅单
     * @return 过磅单
     */
    @Override
    public List<Weigh> selectWeighList(Weigh weigh) {
        return weighMapper.selectWeighList(weigh);
    }

    /**
     * 新增过磅单
     *
     * @param weigh 过磅单
     * @return 结果
     */
    @Override
    public int insertWeigh(Weigh weigh) {
        return weighMapper.insertWeigh(weigh);
    }

    /**
     * 修改过磅单
     *
     * @param weigh 过磅单
     * @return 结果
     */
    @Override
    public int updateWeigh(Weigh weigh) {

        weigh.setCreateDate(DateUtils.getCurrentTime());

        weigh.setId(MD5Utils.md5(weigh.getWeighNum() +weigh.getCreateDate()));
        int updateResult =  weighMapper.updateWeigh(weigh);
        if (0 == updateResult) {
            updateResult = insertWeigh(weigh);
        }

        return updateResult ;
    }

    /**
     * 批量删除过磅单
     *
     * @param ids 需要删除的过磅单主键
     * @return 结果
     */
    @Override
    public int deleteWeighByIds(String[] ids) {
        return weighMapper.deleteWeighByIds(ids);
    }

    /**
     * 删除过磅单信息
     *
     * @param id 过磅单主键
     * @return 结果
     */
    @Override
    public int deleteWeighById(String id) {
        return weighMapper.deleteWeighById(id);
    }
}
